﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

#nullable disable

namespace Ant.EntityFrameworkCore.Model
{
    public partial class AntDB2Context : DbContext
    {
        public AntDB2Context()
        {
        }

        public AntDB2Context(DbContextOptions<AntDB2Context> options)
            : base(options)
        {
        }

        public virtual DbSet<CommodityInfo> CommodityInfos { get; set; }
        public virtual DbSet<CommodityOrder> CommodityOrders { get; set; }
        public virtual DbSet<CommodityType> CommodityTypes { get; set; }
        public virtual DbSet<Inventory> Inventories { get; set; }
        public virtual DbSet<InventoryManagement> InventoryManagements { get; set; }
        public virtual DbSet<Provider> Providers { get; set; }
        public virtual DbSet<ProviderOrder> ProviderOrders { get; set; }
        public virtual DbSet<Role> Roles { get; set; }
        public virtual DbSet<SalesOrder> SalesOrders { get; set; }
        public virtual DbSet<StoreInfo> StoreInfos { get; set; }
        public virtual DbSet<Sysdiagram> Sysdiagrams { get; set; }
        public virtual DbSet<UserInfo> UserInfos { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder.UseSqlServer("server=121.5.10.33;database=AntDB2;uid=sa;pwd=Hsl.12026");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasAnnotation("Relational:Collation", "Chinese_PRC_CI_AS");

            modelBuilder.Entity<CommodityInfo>(entity =>
            {
                entity.HasKey(e => e.Cid)
                    .HasName("_copy_6");

                entity.ToTable("CommodityInfo");

                entity.HasIndex(e => e.StoreId, "IX_CommodityInfo_StoreID");

                entity.Property(e => e.Cid)
                    .HasColumnName("CID")
                    .HasComment("商品主键");

                entity.Property(e => e.BarCode)
                    .HasMaxLength(60)
                    .IsUnicode(false)
                    .HasColumnName("BarCode ")
                    .HasComment("商品条码");

                entity.Property(e => e.Cname)
                    .IsRequired()
                    .HasMaxLength(50)
                    .HasColumnName("CName")
                    .HasComment("商品名称");

                entity.Property(e => e.Ctype)
                    .HasColumnName("CType")
                    .HasComment("商品类型");

                entity.Property(e => e.Price)
                    .HasColumnType("money")
                    .HasComment("商品价格");

                entity.Property(e => e.Specification)
                    .HasMaxLength(60)
                    .HasComment("商品规格");

                entity.Property(e => e.StoreId)
                    .HasColumnName("StoreID")
                    .HasComment("店铺名称");

                entity.Property(e => e.Unit)
                    .HasMaxLength(20)
                    .HasComment("商品单位");

                entity.HasOne(d => d.Store)
                    .WithMany(p => p.CommodityInfos)
                    .HasForeignKey(d => d.StoreId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_CommodityInfo_to_StoreInfo_StoreID");
            });

            modelBuilder.Entity<CommodityOrder>(entity =>
            {
                entity.HasKey(e => e.Coid)
                    .HasName("_copy_10");

                entity.ToTable("CommodityOrder");

                entity.HasIndex(e => e.CommodityId, "IX_CommodityOrder_CommodityID");

                entity.HasIndex(e => e.SalesOrderId, "IX_CommodityOrder_SalesOrderID");

                entity.Property(e => e.Coid)
                    .HasColumnName("COID")
                    .HasComment("数据ID");

                entity.Property(e => e.CommodityId)
                    .HasColumnName("CommodityID")
                    .HasComment("商品ID");

                entity.Property(e => e.CopeWith)
                    .HasColumnType("decimal(18, 0)")
                    .HasComment("应付");

                entity.Property(e => e.Count).HasComment("数量");

                entity.Property(e => e.SalesOrderId)
                    .HasColumnName("SalesOrderID")
                    .HasComment("单号ID");

                entity.Property(e => e.UnitPrice)
                    .HasColumnType("decimal(18, 0)")
                    .HasComment("单价");

                entity.HasOne(d => d.Commodity)
                    .WithMany(p => p.CommodityOrders)
                    .HasForeignKey(d => d.CommodityId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_CommodityOrder_to_CommodityInfo_CID");

                entity.HasOne(d => d.SalesOrder)
                    .WithMany(p => p.CommodityOrders)
                    .HasForeignKey(d => d.SalesOrderId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_CommodityOrder_to_SalesOrder_SalesID");
            });

            modelBuilder.Entity<CommodityType>(entity =>
            {
                entity.HasKey(e => new { e.TypeName, e.StoreId })
                    .HasName("_copy_2");

                entity.ToTable("CommodityType");

                entity.HasIndex(e => e.StoreId, "IX_CommodityType_StoreID");

                entity.Property(e => e.TypeName)
                    .HasMaxLength(20)
                    .HasComment("类别名称");

                entity.Property(e => e.StoreId)
                    .HasColumnName("StoreID")
                    .HasComment("所属店铺");

                entity.Property(e => e.TypeId)
                    .ValueGeneratedOnAdd()
                    .HasColumnName("TypeID")
                    .HasComment("商品类别主键");

                entity.HasOne(d => d.Store)
                    .WithMany(p => p.CommodityTypes)
                    .HasForeignKey(d => d.StoreId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_CommodityType_to_StoreInfo_StoreID");
            });

            modelBuilder.Entity<Inventory>(entity =>
            {
                entity.HasKey(e => e.Iid)
                    .HasName("_copy_7");

                entity.ToTable("Inventory");

                entity.HasIndex(e => e.CommodityId, "IX_Inventory_CommodityID");

                entity.HasIndex(e => e.StoreId, "IX_Inventory_StoreID");

                entity.Property(e => e.Iid)
                    .HasColumnName("IID")
                    .HasComment("仓库索引");

                entity.Property(e => e.CommodityId)
                    .HasColumnName("CommodityID")
                    .HasComment("商品ID");

                entity.Property(e => e.Count).HasComment("货物数量");

                entity.Property(e => e.StoreId)
                    .HasColumnName("StoreID")
                    .HasComment("店铺ID");

                entity.HasOne(d => d.Commodity)
                    .WithMany(p => p.Inventories)
                    .HasForeignKey(d => d.CommodityId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Inventory_to_CommunityInfo_CID");

                entity.HasOne(d => d.Store)
                    .WithMany(p => p.Inventories)
                    .HasForeignKey(d => d.StoreId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Inventory_to_StorInfo_StoreID");
            });

            modelBuilder.Entity<InventoryManagement>(entity =>
            {
                entity.HasKey(e => e.Imid)
                    .HasName("PK__Inventor__8DF35042246AEA2F");

                entity.ToTable("InventoryManagement");

                entity.HasIndex(e => e.InventoryId, "IX_InventoryManagement_InventoryID");

                entity.HasIndex(e => e.Salesman, "IX_InventoryManagement_Salesman");

                entity.HasIndex(e => e.StoreId, "IX_InventoryManagement_StoreID");

                entity.Property(e => e.Imid).HasColumnName("IMID");

                entity.Property(e => e.Count)
                    .HasMaxLength(10)
                    .IsFixedLength(true);

                entity.Property(e => e.InventoryId).HasColumnName("InventoryID");

                entity.Property(e => e.StoreId).HasColumnName("StoreID");

                entity.HasOne(d => d.Inventory)
                    .WithMany(p => p.InventoryManagements)
                    .HasForeignKey(d => d.InventoryId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_InventoryManagement_Inventory");

                entity.HasOne(d => d.SalesmanNavigation)
                    .WithMany(p => p.InventoryManagements)
                    .HasForeignKey(d => d.Salesman)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_InventoryManagement_UserInfo");

                entity.HasOne(d => d.Store)
                    .WithMany(p => p.InventoryManagements)
                    .HasForeignKey(d => d.StoreId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_InventoryManagement_StoreInfo");
            });

            modelBuilder.Entity<Provider>(entity =>
            {
                entity.HasKey(e => e.Pid)
                    .HasName("_copy_4");

                entity.ToTable("Provider");

                entity.HasIndex(e => e.StroeId, "IX_Provider_StroeID");

                entity.Property(e => e.Pid).HasColumnName("PID");

                entity.Property(e => e.Pname)
                    .IsRequired()
                    .HasMaxLength(50)
                    .HasColumnName("PName")
                    .HasComment("进货商名称");

                entity.Property(e => e.Pphone)
                    .IsRequired()
                    .HasMaxLength(50)
                    .HasColumnName("PPhone")
                    .HasComment("进货商联系方式");

                entity.Property(e => e.StroeId)
                    .HasColumnName("StroeID")
                    .HasComment("关联店铺");

                entity.HasOne(d => d.Stroe)
                    .WithMany(p => p.Providers)
                    .HasForeignKey(d => d.StroeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Provider_to_StoreInfo_StoreID");
            });

            modelBuilder.Entity<ProviderOrder>(entity =>
            {
                entity.HasKey(e => e.Poid)
                    .HasName("_copy_5");

                entity.ToTable("ProviderOrder");

                entity.HasIndex(e => e.CommodityId, "IX_ProviderOrder_CommodityID");

                entity.HasIndex(e => e.ProvoderId, "IX_ProviderOrder_ProvoderID");

                entity.Property(e => e.Poid)
                    .HasColumnName("POID")
                    .HasComment("记录ID");

                entity.Property(e => e.CommodityId)
                    .HasColumnName("CommodityID")
                    .HasComment("提供货物的ID");

                entity.Property(e => e.ProvoderId)
                    .HasColumnName("ProvoderID")
                    .HasComment("供货商ID");

                entity.HasOne(d => d.Commodity)
                    .WithMany(p => p.ProviderOrders)
                    .HasForeignKey(d => d.CommodityId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_ProviderOrder_to_CommodityInfo");

                entity.HasOne(d => d.Provoder)
                    .WithMany(p => p.ProviderOrders)
                    .HasForeignKey(d => d.ProvoderId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_ProviderOrder_to_Provider_PID");
            });

            modelBuilder.Entity<Role>(entity =>
            {
                entity.ToTable("Role");

                entity.Property(e => e.RoleId)
                    .HasColumnName("RoleID")
                    .HasComment("角色");

                entity.Property(e => e.RoleName)
                    .IsRequired()
                    .HasMaxLength(20)
                    .HasComment("角色名称");
            });

            modelBuilder.Entity<SalesOrder>(entity =>
            {
                entity.HasKey(e => e.SalesId)
                    .HasName("_copy_1");

                entity.ToTable("SalesOrder");

                entity.HasIndex(e => e.Salesman, "IX_SalesOrder_Salesman");

                entity.HasIndex(e => e.StroeId, "IX_SalesOrder_StroeID");

                entity.Property(e => e.SalesId)
                    .HasColumnName("SalesID")
                    .HasComment("销售单ID");

                entity.Property(e => e.Discount)
                    .HasColumnType("money")
                    .HasComment("折扣金额");

                entity.Property(e => e.Salesman).HasComment("销售员");

                entity.Property(e => e.StroeId)
                    .HasColumnName("StroeID")
                    .HasComment("店铺ID");

                entity.Property(e => e.Sum)
                    .HasColumnType("money")
                    .HasComment("金额");

                entity.Property(e => e.Time).HasDefaultValueSql("(getdate())");

                entity.HasOne(d => d.SalesmanNavigation)
                    .WithMany(p => p.SalesOrders)
                    .HasForeignKey(d => d.Salesman)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_SalesOrder_to_UserInfo_UserID");

                entity.HasOne(d => d.Stroe)
                    .WithMany(p => p.SalesOrders)
                    .HasForeignKey(d => d.StroeId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_eatsetset");
            });

            modelBuilder.Entity<StoreInfo>(entity =>
            {
                entity.HasKey(e => e.StoreId)
                    .HasName("_copy_3");

                entity.ToTable("StoreInfo");

                entity.Property(e => e.StoreId)
                    .HasColumnName("StoreID")
                    .HasComment("店铺编号");

                entity.Property(e => e.StoreLocation)
                    .HasMaxLength(20)
                    .HasComment("店铺地址");

                entity.Property(e => e.StoreName)
                    .IsRequired()
                    .HasMaxLength(50)
                    .HasComment("店铺名称");
            });

            modelBuilder.Entity<Sysdiagram>(entity =>
            {
                entity.HasKey(e => e.DiagramId)
                    .HasName("PK__sysdiagr__C2B05B613015BB27");

                entity.ToTable("sysdiagrams");

                entity.HasIndex(e => new { e.PrincipalId, e.Name }, "UK_principal_name")
                    .IsUnique();

                entity.Property(e => e.DiagramId).HasColumnName("diagram_id");

                entity.Property(e => e.Definition).HasColumnName("definition");

                entity.Property(e => e.Name)
                    .IsRequired()
                    .HasMaxLength(128)
                    .HasColumnName("name");

                entity.Property(e => e.PrincipalId).HasColumnName("principal_id");

                entity.Property(e => e.Version).HasColumnName("version");
            });

            modelBuilder.Entity<UserInfo>(entity =>
            {
                entity.HasKey(e => e.UserId)
                    .HasName("_copy_8");

                entity.ToTable("UserInfo");

                entity.HasIndex(e => e.UserRole, "IX_UserInfo_UserRole");

                entity.HasIndex(e => e.UserStore, "IX_UserInfo_UserStoreNavigationStoreId");

                entity.Property(e => e.UserId)
                    .HasColumnName("UserID")
                    .HasComment("用户编号");

                entity.Property(e => e.UserEmail)
                    .IsRequired()
                    .HasMaxLength(20)
                    .HasComment("用户邮箱");

                entity.Property(e => e.UserName)
                    .IsRequired()
                    .HasMaxLength(10)
                    .IsUnicode(false)
                    .HasComment("用户名称");

                entity.Property(e => e.UserPwd)
                    .IsRequired()
                    .HasMaxLength(30)
                    .HasComment("用户密码");

                entity.Property(e => e.UserRole).HasComment("用户角色");

                entity.HasOne(d => d.UserRoleNavigation)
                    .WithMany(p => p.UserInfos)
                    .HasForeignKey(d => d.UserRole)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_UserInfo_to_Role_RoleID");

                entity.HasOne(d => d.UserStoreNavigation)
                    .WithMany(p => p.UserInfos)
                    .HasForeignKey(d => d.UserStore)
                    .HasConstraintName("FK_UserInfo_StoreInfo_UserStoreNavigationStoreId");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
